<template>
  <!-- 法规平台 -->
  <div class="app-container">
    <el-button
      @click="addshowFn"
      type="primary"
      v-hasPermi="['market:depositPresent:add']"
      >新增</el-button
    >
    <!-- <h1>法规平台</h1> -->
    <div class="boxlaw">
      <ComTable
        v-hasPermi="['market:depositPresent:edit']"
        @handleStatusChange="StatusChangeFn"
        @handleCurrentChange="CurrentPageChangeFn"
        @handleSizeChange="currentPageSizeChangeFn"
        :key="random"
        :list="tableList"
        :modes="tableModes"
        :config="{ border: true, loading }"
        :pagination="{ total: paging.total, pageNum: paging.pageNum }"
      >
        <el-table-column #default="{ row }" align="left">
          <template>
            <el-button
              plain
              size="mini"
              @click="editShowFn(row)"
              v-hasPermi="['market:depositPresent:getInfo']"
              type="primary"
              >修改</el-button
            >
            <el-button
              plain
              size="mini"
              type="danger"
              @click="deleteFn(row)"
              v-hasPermi="['market:depositPresent:remove']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </ComTable>
    </div>
    <AddAndEditAmount
      @eventGetList="getDepositPresentListFn"
      ref="addAndEditAmount"
      @EventParams="saveFn"
      :dialogVisible.sync="dialogVisible"
    ></AddAndEditAmount>
  </div>
</template>

<script>
import ComForm from "../../../components/comForm.vue";
import ComSelect from "../../../components/comSelect.vue";
import ComTable from "../../../components/comTable.vue";
import comForm from "../../../components/comForm.vue";
// import { getdocGetTypeApi } from "@/wss/api/ContentSupervision.js";

import {
  getDepositPresentListApi,
  getDepositPresentStatusApi,
  getDepositPresentAddApi,
  getDepositPresentEditApi,
} from "@/wss/api/financial/Recharge/depositPresent.js";

import AddAndEditAmount from "./addAndEditAmount.vue";
export default {
  name: "laws",
  dicts: ["sys_normal_disable"],
  components: { ComSelect, ComForm, comForm, ComTable, AddAndEditAmount },

  data() {
    return {
      dialogVisible: false,
      initSelectValue: "",
      // 加载
      loading: false,
      paging: { pageNum: 1, pageSize: 10, total: 10 },
      // 切换筛选状态，不更新bug修复
      random: "",
      // 当前筛选的状态
      currentSelect: "",

      // 表格的数据
      tableList: [],
      tableModes: [
        {
          type: "selection",
        },
        {
          showOverflowTooltip: true,

          width: 200,
          label: "充值金额（元）",
          mode: "amount",
          showOverflowTooltip: true,
        },
        {
          label: "赠送卡券（元）",
          mode: "quota",
        },
        {
          label: "状态",
          mode: "status",
          showOverflowTooltip: true,
        },
        {
          label: "创建时间",
          mode: "createTime",
        },
      ],
    };
  },

  mounted() {
    this.getDepositPresentListFn();
  },
  methods: {
    // 保存于修改
    async saveFn(data) {
      // 修改
      if (data.idStr) {
        data.id = data.idStr;
        let { code, msg } = await getDepositPresentEditApi(data);
        console.log(code);
        if (code == 200) {
          this.$modal.msgSuccess(msg);
          this.getDepositPresentListFn();
        }
      } else {
        // 新增
        let { code, msg } = await getDepositPresentAddApi(data);
        if (code == 200) {
          this.$modal.msgSuccess(msg);
          this.getDepositPresentListFn();
        }
      }

      // console.log(result);
    },
    // 删除
    async deleteFn(row) {
      try {
        await this.$modal.confirm("你确定要删除吗");
        let { code, msg } = await getDepositPresentStatusApi(row.idStr);
        if (code) {
          this.$modal.msgSuccess(msg);
          this.getDepositPresentListFn();
        }
      } catch (error) {}
    },
    addshowFn() {
      this.dialogVisible = true;
    },
    // 修改
    editShowFn(row) {
      this.$refs.addAndEditAmount.getDetaiFn(row);
      this.dialogVisible = true;
    },
    // 当前页发生改变时候
    CurrentPageChangeFn(pageNUm) {
      this.paging.pageNum = pageNUm;
      this.getDepositPresentListFn();
    },
    // 页容量发生改变时候
    currentPageSizeChangeFn(pageSize) {
      this.paging.pageSize = pageSize;
      this.getDepositPresentListFn();
    },

    // 获取列表数据
    async getDepositPresentListFn() {
      this.loading = true;
      let { rows, code, total } = await getDepositPresentListApi(this.paging);

      console.log(rows, "充值金额");
      if (code == 200) {
        this.tableList = rows;
        this.paging.total = total;

        this.loading = false;
      }
    },
    // 修改状态
    async StatusChangeFn(row) {
      row.id = row.idStr;

      let { code, msg } = await getDepositPresentEditApi(row);
      if (code == 200) {
        this.$modal.msgSuccess(msg);
        this.getDepositPresentListFn();
      }
    },
  },
};
</script>

<style lang ="scss" scoped>
.comform {
  margin-top: 20px;
}
</style>